// JavaScript Document
var PICTURE = function(){
	var ITEM = function(){
		//封装图片展示的模块标签
		var ITEM = function(){
			this.li = null;
			this.pictureContainer = null;
			this.picture = null;
			this.pictureInfo = null;
			this.userPhoto = null;	
			this.userName = null;
			this.replyTime = null;
		}
		ITEM.prototype = {
			//初始化标签
			init:function(){
				var self = this;
				self.li = create("li");
				self.pictureContainer = create("section");
				self.picture = create("img");
				self.pictureInfo = create("section");
				self.userPhoto = create("img");
				self.userName = create("h4");
				self.replyTime = create("span");
				
				self.pictureContainer.className = "pictureContainer";
				self.pictureInfo.className = "pictureInfo";	
			},	
			//组合标签
			get:function(d){
				var self = this;
				if(self.li == null){
					self.init();	
				}
				//数据绑定
				//self.picture.src = d.pictureSrc;
				reloadPicture(self.picture,d.pictureSrc);
				self.userPhoto.src = d.userPhoto;
				self.userName.innerHTML = d.userName;
				self.replyTime.innerHTML = "评论"+d.replyTimes;
				
				self.pictureContainer.appendChild(self.picture);
				self.pictureInfo.appendChild(self.userPhoto);
				self.pictureInfo.appendChild(self.userName);
				self.pictureInfo.appendChild(self.replyTime);
				
				self.li.appendChild(self.pictureContainer);
				self.li.appendChild(self.pictureInfo);
				
				return self.li;	
			}
		}
		//返回一个对象
		return new ITEM();
	}
	
	var create = function(tagName){
		return document.createElement(tagName);	
	}
	var get = function(cid){
		return document.getElementById(cid);
	}
	//最新图片展示类
	var picture = function(){
		this.data = null;
		this.frag = document.createDocumentFragment();
		this.container = null;
	}
	//方法
	picture.prototype = {
		init:function(data){
			var self = this;
			self.data = data;
			self.container = document.getElementById("pictureLast");	
		},
		//最新模块图片展示
		showLast:function(data){
			var self = this;			
			if(self.container == null){
				self.init(data);	
			}
			if(self.data == null){
				return;	
			}
			//遍历数据数组
			//数据数组满足json标准格式
			//["time":"2012年12月12日","info":[{"pictureSrc":"","userPhoto":"","userName":"","replyTimes":""}]]
			for(var i =0;i<self.data.length;i++){
				var d = data[i];
				var section = create("section");
				section.className = "lastInner";
				var time = create("h2");
				time.className = "time shadow";
				time.innerHTML = d.time;
				var ul = create("ul");
				ul.className = "lastUl";
				for(var j =0;j<d.info.length;j++){
					//新建一个图片展示模块
					var li = ITEM().get(d.info[j]);
					ul.appendChild(li);
				}
				
				section.appendChild(time);
				section.appendChild(ul);
				self.frag.appendChild(section);
			}
			self.container.appendChild(self.frag);
		},
		//朋友图片模块图片展示
		showFriend:function(data){
			var self = this;			
			if(self.container == null){
				self.init(data);	
			}
			if(self.data == null){
				return;	
			}
			//获取界面结点
			var leftUl = get("leftPicture");
			var middleUl = get("middlePicture");
			var rightUl = get("rightPicture");
			
			var leftFrag = document.createDocumentFragment();
			var leftFrag = document.createDocumentFragment();
			var leftFrag = document.createDocumentFragment();
			
			var lh = 200;
			var mh = 0;
			var rh = 0;
			for(var i =0;i<data.length;i++){
				var li = ITEM().get(data[i]);
				
				if(lh<=mh&&lh<=rh){
					leftFrag.appendChild(li);
					lh = lh + data.height;
				}
				else if(mh<lh&&mh<=rh){
					middleFrag.appendChild(li);
					mh = mh + data.height;
				}
				else if(rh<mh&&rh<lh){
					rightFrag.appendChild(li);
					rh = rh + data.height;
				}
			}
			leftUl.appendChild(leftFrag);
			middleUl.appendChild(middleFrag);
			rightUl.appendChild(rightFrag);
		},
	}
	return new picture();
}



